<template>
  <div>
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <span
            v-for="item in catorylist"
            :key="item.id"
            :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']"
            @click="getphoto(item.id)"
          >
            {{ item.title }}
          </span>
        </div>
      </div>
    </div>

    <ul class="lazy-ui">
      <router-link v-for="item in photolist" :key="item.id" :to="'/home/photodetail/'+item.id" tag="li">
        <img v-lazy="item.img_url" />
        <div class="info">
          <h1 class="info-title">{{ item.title }}</h1>
          <div class="info-content" v-html="item.content"></div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
import mui from "../../../lib/mui/js/mui.js";

export default {
  data() {
    return {
      catorylist: [],
      photolist: [],
    };
  },
  methods: {
    async getcatory() {
      const { data } = await this.$http.get("/api/getimgcategory");
      if (data.status == 0) {
        this.catorylist = data.message;
        this.catorylist.unshift({ id: 0, title: "全部" });
      }
    },
    async getphoto(id) {
      const { data } = await this.$http.get("/api/getimages/" + id);
      if (data.status == 0) {
        this.photolist = data.message;
        this.photolist.forEach((item) => {
          item.img_url =
            "https://f10.baidu.com/it/u=2891956671,2576939620&fm=173&app=49&f=JPEG?w=640&h=472&s=EF63B10C82620FAD380C708803007096&access=215967316";
        });
      }
    },
  },
  created() {
    this.getcatory();
    this.getphoto(0);
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005, //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
};
</script>

<style lang="scss" scoped>
.mui-slider {
  touch-action: pan-x;
}

.lazy-ui {
  background-color: #fff;
  margin: 10px;
  padding: 0;
  li {
    background-color: #cfcfcf;
    position: relative;
    box-shadow: 0 0 7px grey;
    & + li {
      padding-top: 5px;
    }
    img {
      width: 100%;
      vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
    .info {
      position: absolute;
      bottom: 0;
      background-color: rgba(0,0,0,0.5);
      color:white;
      max-height: 86px;
      .info-title {
        font-size: 15px;
        text-align: center;
      }
      .info-content {
        font-size: 14px;
        text-align: left;
        text-indent: 2em;
      }
    }
  }
}
</style>